package com.suedawn.bookmanagesystem.controller;

import com.suedawn.bookmanagesystem.entity.UserType;
import com.suedawn.bookmanagesystem.service.UserTypeService;
import com.suedawn.bookmanagesystem.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class UserTypeController {
    @Autowired
    private UserTypeService userTypeService;

    @GetMapping("/user/types")
    public R list(){
        List<UserType> list = userTypeService.list();
        return list != null ? R.ok(list) : R.error();
    }

    @PostMapping("/user/type/save")
    public R add(@RequestBody UserType userType){
        boolean save = userTypeService.save(userType);
        return save?R.ok():R.error();
    }

    @DeleteMapping("/user/type/del")
    public R delete(Integer typeId){
        boolean b = userTypeService.removeById(typeId);
        return b?R.ok():R.error();
    }
}
